<template>
  <!-- 房间入住情况页面 -->
  <div class="app-container">
    <!-- 搜索 -->
    <searchForm
      :formOptions="formOptionsInfor"
      @onSearch="onSearch"
      @onReset="onReset"
      :formLabelWidth="formLabelWidth"
      v-show="showSearch"
    />
    <el-row :gutter="10" class="mb8">
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-table :data="tableData">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column prop="houseNo" label="所属公寓楼" align="center">
      </el-table-column>
      <el-table-column prop="roomNo" label="房间号" align="center">
      </el-table-column>
      <el-table-column prop="roomType" label="房间类型" align="center">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_room_type" :value="scope.row.roomType"></dict-tag>
        </template>
      </el-table-column>
      <el-table-column prop="sex" label="性别要求" align="center">
      </el-table-column>
      <el-table-column prop="roomPersonNum" label="总床位" align="center">
      </el-table-column>
      <el-table-column prop="stayNum" label="已入住人数" align="center">
      </el-table-column>
      <el-table-column prop="delFlag" label="房间状态" align="center">
      </el-table-column>
      <el-table-column prop="isLeader" label="宿舍长" align="center">
      </el-table-column>
      <el-table-column prop="studentType" label="标记" align="center">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.basic_student_mark" :value="scope.row.studentType"></dict-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="160">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="checkin(scope.row)"
            >查看入住信息</el-button
          >
          <!-- <el-button size="mini" type="text" @click="master(scope.row)"
            >分配社长</el-button
          > -->
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog :title="title" :visible.sync="open" width="60%" append-to-body>
      <!-- <searchForm
        :formOptions="checkInfor"
        @onSearch="onCheckInfor"
        :formLabelWidth="checkInforWidth"
      /> -->
      <el-table :data="roomBedData">
        <!-- <el-table-column type="selection" width="55" align="center" /> -->
        <el-table-column prop="bedNo" label="床位号" align="center">
        </el-table-column>
        <el-table-column prop="studentNo" label="学号" align="center">
        </el-table-column>
        <el-table-column prop="studentname" label="姓名" align="center">
        </el-table-column>
        <el-table-column prop="studentType" label="标记" align="center">
          <template slot-scope="scope">
          <dict-tag :options="dict.type.basic_student_mark" :value="scope.row.studentType"></dict-tag>
        </template>
        </el-table-column>
        <el-table-column prop="roomType" label="房间类型" align="center">
          <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_room_type" :value="scope.row.roomType"></dict-tag>
        </template>
        </el-table-column>
        <el-table-column prop="college" label="院系" align="center">
        </el-table-column>
        <el-table-column prop="gradeName" label="年级" align="center">
        </el-table-column>
        <el-table-column prop="specialityName" label="专业" align="center">
        </el-table-column>
        <el-table-column prop="className" label="班级" align="center">
        </el-table-column>
        <el-table-column prop="counsellorName" label="辅导员" align="center">
        </el-table-column>
        <!-- <el-table-column prop="name" label="教工号" align="center">
        </el-table-column> -->
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-popconfirm
              title="确定将该同学设为舍长吗？"
              @confirm="determine(scope.row)"
            >
              <el-button slot="reference" size="mini" type="text"
                >设为舍长</el-button
              >
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <!-- <el-dialog
      :title="title"
      :visible.sync="housemaster"
      width="60%"
      append-to-body
    >
      <searchForm
        :formOptions="housemasters"
        @onSearch="onHousemasterInfor"
        :formLabelWidth="checkInforWidth"
      />

      <el-table :data="tableData">
        <el-table-column prop="name" label="床位号" align="center">
        </el-table-column>
        <el-table-column prop="name" label="所在班级" align="center">
        </el-table-column>
        <el-table-column prop="name" label="学号" align="center">
        </el-table-column>
        <el-table-column prop="name" label="是否舍长" align="center">
        </el-table-column>
        <el-table-column prop="name" label="姓名" align="center">
        </el-table-column>
        <el-table-column prop="name" label="入住状态" align="center">
        </el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-popconfirm
              title="确定将该同学设为舍长吗？"
              @confirm="determine(scope.row)"
            >
              <el-button slot="reference" size="mini" type="text"
                >设为舍长</el-button
              >
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-dialog> -->
  </div>
</template>

<script>
import {roomAccommodationInfoList,allocationLeaderInit} from '@/api/apartment/roomAccommodation'
import {list} from '@/api/apartment/roomBedlist'
import searchForm from "@/components/Search/searchForm.vue";
export default {
  components: { searchForm },
  dicts: ["basic_student_mark",'sys_room_type'],
  data() {
    return {
      // 查询
      formOptionsInfor: [
        {
          label: "所属公寓楼",
          prop: "houseNo",
          element: "el-input",
          placeholder: "请输入公寓楼",
        },
        {
          label: "房间号",
          prop: "roomNo",
          element: "el-input",
          placeholder: "请输入房间号",
        },
        {
          label: "房间状态",
          prop: "delFlag",
          element: "el-select",
          options: [
            { label: "未住满", value: "1" },
            { label: "已住满", value: "2" },
          ],
          placeholder: "请选择房间类型",
        },
        {
          label: "性别要求",
          prop: "sex",
          element: "el-select",
          options: [
            { label: "男", value: "1" },
            { label: "女", value: "2" },
          ],
          placeholder: "请选择性别要求",
        },
      ],
      // 分配舍长查询条件
      housemasters: [
        {
          label: "床位号",
          prop: "cw",
          element: "el-input",
          placeholder: "请输入床位号",
        },
      ],
      checkInforWidth: "60px",
      tableData: [],
      roomBedData: [], // 宿舍数据
      total: 0,
      formLabelWidth: "85px",
      masterInforWidth: "80px",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      title: "",
      open: false,
      housemaster: false, // 分配舍长
      showSearch: true,

    };
  },
  created() {
    this.getList()
  },
  methods: {
    // 获取搜索表单提交的数据
    onSearch(val) {
      // 查询条件和分页数据合并
      this.queryParams = Object.assign(this.queryParams, val);
      this.queryParams.pageNum = 1;
      this.getList();
    },
      // 重置
      onReset(data) {
      // console.log(data);
      this.queryParams.pageNum = 1;
      this.queryParams = Object.assign(this.queryParams, data);
      // console.log(this.queryParams);
      this.getList();
    },
    onCheckInfor(val) {
      // 查询条件和分页数据合并
      const arr = Object.assign(this.queryParams, val);
      this.queryParams.pageNum = 1;
    },
    onHousemasterInfor(val) {
      // 查询条件和分页数据合并
      const arr = Object.assign(this.queryParams, val);
      this.queryParams.pageNum = 1;
    },
    /** 查询角色列表 */
    getList() {
      this.loading = true;
      roomAccommodationInfoList(this.queryParams).then(
        (response) => {
          this.tableData = response.rows;
          this.total = response.total;
        }
      );
    },
    // 查看入职信息
    checkin(row) {
      this.open = true;
      this.title = "查看入住信息";
      list({roomId: row.roomId}).then((response)=> {
        this.roomBedData = response.rows;
      })
    },
    // // 分配舍长
    // master(row) {
    //   this.title = "分配舍长";
    //   this.housemaster = true;
    // },
    // 确定设为舍长按钮
    determine(row) {
      console.log(row, "确定");
      allocationLeaderInit(row).then((response)=> {
        if(response.code == 200) {
          this.$modal.msgSuccess("舍长设置成功");
          this.open = false;
          this.getList()
        }
      })

    },
  },
};
</script>

<style>
</style>